home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / serien / purity / nr.25 / dynamic / dynamic_demo.pas < prev    next >
Pascal/Delphi Source File  |  1995-04-23  |  28KB  |  649 lines

  1. {*******************************************************************}
  2. { DynamicLists V1.2                                                 }
  3. {*******************************************************************}
  4. { Een demonstratie hoe je met dynamic lists kunt werken.            }
  5. {*******************************************************************}
  6. { Door Hans Luyten                                                  }
  7. {                                                                   }
  8. { Compiler: HiSpeed Pascal v2.0 (Amiga)                             }
  9. {           (Werkt ook foutloos met: Turbo Pascal >v5.5  (MSDos)    }
  10. {                                en: HiSpeed Pascal >v2.4 (Atari))  }
  11. {           HiSpeed Pascal: (c) 1992 HiSoft                         }
  12. {           Turbo Pascal:   (c) 1991 Borland                        }
  13. {                                                                   }
  14. { Remark: VGAHi wordt door de Amiga en Atari ondersteunt !!         }
  15. {                                                                   }
  16. { Compiler options: Range Check, Stack Check, I/O Check             }
  17. {                                                                   }
  18. {*******************************************************************}
  19. { Versie: 1.0, 17 September 1993.                                   }
  20. {                                                                   }
  21. { Versie: 1.1, 18 September 1993, Toevoeging: Delete Node,          }
  22. {                                             Position Insert.      }            
  23. { Versie: 1.2, 19 September 1993, Bug removed bij 'Delete' en       }
  24. {                                 'positionInsert', tevens index-   }
  25. {                                 balk voor nodenummering           }
  26. {                                 toegevoegd                        }
  27. {*******************************************************************}
  28. PROGRAM DynamicLists;
  29.  
  30. uses
  31.   Graph,Crt;
  32. TYPE                                             { Onze LINKEDLIST  } 
  33.   StudentP    = ^StudentData;
  34.   StudentData = RECORD
  35.                   Naam   : string[10];
  36.                   ANr    : string[10];
  37.                   Next   : StudentP;
  38.                 END;
  39. CONST
  40.   CX      =  8;                                  { Karakter afstand }
  41.   CY      = 8;                                   { Regel afstand    }
  42.   FormH   = 20;                                  { Node Hoogte      }
  43.   FormW   = 95;                                  { Node Breedte     }      
  44.   Dist    =  5;                                  { Block afstand    }
  45.   MaxNodes= 5;                                   { Maximum Nodes    }
  46.  
  47. VAR 
  48.   StudentHead : StudentP;
  49.   VGAMode     : BOOLEAN;
  50.   c           : CHAR;
  51.   OldPalette  : PaletteType;
  52.   ActiveNodes : INTEGER;
  53.   
  54. {*******************************************************************}
  55. {************************* Alg-Procedures **************************}
  56. {*******************************************************************}
  57.  
  58. {*******************************************************************}
  59. { FixBar(x,y,x2,y2,Color1,Color2);                                  }
  60. { Vervangt SetColor, SetFillStyle en Bar in 1 procedure.            }
  61. {*******************************************************************}
  62. { PRE  : VGAMode                                                    }
  63. { POST : Bar getekend.                                              }
  64. {*******************************************************************}
  65. PROCEDURE FixBar(x,y,x2,y2 : INTEGER; color1, color2 : INTEGER);
  66. BEGIN
  67.   SetColor(Color1);
  68.   SetFillStyle(SolidFill,Color2);
  69.   Bar(x,y,x2,y2);
  70. END;
  71.  
  72. {*******************************************************************}
  73. { LeesInput(x,y,'Naam:',String);                                    }
  74. { Leest het keyboard tijdens grafisch scherm (ReadLn geeft probleem)}
  75. { van maximaal 10 tekens !                                          }
  76. {*******************************************************************}
  77. { PRE  : VGAMode=TRUE                                               }
  78. { POST : In String staat de input.                                  }
  79. {*******************************************************************}
  80. PROCEDURE LeesInput(x,y: INTEGER; header : String; 
  81.                     VAR TEXT : String);
  82. CONST
  83.   MaxLengte = 10;
  84. VAR
  85.   Letter : CHAR;
  86.   Teller : INTEGER;
  87. BEGIN
  88.   OutTextXY(x+CX,y+CY,header);
  89.   TEXT:='';
  90.   FOR Teller:=1 TO MaxLengte DO
  91.     BEGIN
  92.       Letter:=ReadKey;
  93.       IF ((Letter>CHR(31)) AND (Letter<CHR(127))) THEN
  94.         BEGIN                                 { Letters/Cijfers ?   }
  95.           TEXT:=concat(TEXT,Letter);          { Nieuwe letter erbij }
  96.           OutTextXY(x+CX*(Teller+6),y+CY,Letter);
  97.         END          
  98.       ELSE IF ((Letter=CHR(13)) OR (Letter=CHR(10))) THEN
  99.         exit                                  { RETURN = chr(13)    }
  100.       ELSE IF Letter=CHR(8) THEN
  101.         BEGIN                                 { Backspace = chr(8)  }
  102.           IF Teller>2 THEN
  103.             BEGIN
  104.               Teller:=Teller-2; { backspace + voorganger = 2 chars !}
  105.               delete(TEXT,Teller+1,1);        { verwijder laatste   }
  106.               FixBar(x+CX*(Teller+7),y+CY,x+CX*(Teller+8),y+2*CY,
  107.                      Yellow,Yellow);
  108.               SetColor(DarkGray);
  109.             END
  110.           ELSE
  111.             BEGIN
  112.               TEXT:='';                       { Alles wissen !!     }
  113.               Teller:=0;                      { = opnieuw invoeren  }
  114.               FixBar(x+CX*(Teller+7),y+CY,x+CX*(Teller+8),y+2*CX,
  115.                      Yellow,Yellow);
  116.               SetColor(DarkGray);
  117.             END;
  118.         END
  119.       ELSE 
  120.         Letter:=ReadKey;                      { Ctrl-codes opvangen }
  121.     END;
  122. END;
  123.  
  124. {*******************************************************************}
  125. {************************* GFX-Procedures **************************}
  126. {*******************************************************************}
  127.   
  128. {*******************************************************************}
  129. { OpenVGAScreen();                                                  }
  130. { Deze procedure zal proberen een VGAScherm te openen (600x480)     }
  131. { Tevens worden de gebruikte kleuren aangepast.                     }
  132. { Note: VGAHi wordt door HiSpeed Pascal (Amiga en Atari) en         }
  133. {       Turbo-Pascal (PC) simuleert/ondersteund !!                  }
  134. {*******************************************************************}
  135. { PRE  : De variabele VGAMode (boolean) moet geinitialiseerd        }
  136. {        zijn als globale variabele.                                }
  137. { POST : Als het VGA-scherm open is, is VGAMode=TRUE.               }
  138. {        Zoniet, dan is VGAMode=FALSE.                              }
  139. {*******************************************************************}
  140. PROCEDURE OpenVGAScreen;
  141. VAR
  142.   GfxDriver, DriverMode, ErrorCode : INTEGER;
  143. BEGIN
  144.   GfxDriver:=Detect;                             { Gfx mogelijk ?   }
  145.   InitGraph(GfxDriver,DriverMode,'');            { Gfx Init         }
  146.   SetGraphMode(VGAHi);                           { Probeer VGA ..   }
  147.   ErrorCode:=GraphResult;                        { VGA gelukt ??    }
  148.   IF ErrorCode=grOK THEN
  149.     VGAMode:=TRUE                                { VGA Gelukt...    }
  150.   ELSE
  151.     VGAMode:=FALSE;                              { Niks geen VGA !  }
  152.   IF VGAMode=TRUE THEN
  153.     BEGIN
  154.       GetPalette(OldPalette);                    { Actieve Palette  }
  155.       SetRGBPalette(Black   ,0 ,0 ,0 );          { opslaan en       }
  156.       SetRGBPalette(Blue    ,0 ,0 ,63);          { instellen voor   }
  157.       SetRGBPalette(Green   ,0 ,63,0 );          { correcte kleur-  }
  158.       SetRGBPalette(Red     ,63,0 ,0 );          { Palette.         }
  159.       SetRGBPalette(Yellow  ,63,63,0 );          { Ook voor Amiga,  }
  160.       SetRGBPalette(White   ,63,63,63);          { Atari en PC !!   }
  161.       SetRGBPalette(DarkGray,20,20,20);          { HIGHSPEED PASCAL }
  162.       SetColor(Yellow);
  163.       OutTextXY(180,470,'(C) 1993 By Hans Luyten. A-Yeah!');
  164.     END;  
  165. END;
  166.  
  167. {*******************************************************************}
  168. { RestoreColors;                                                    }
  169. { Herstelt oude palette... (als het goed is...)                     }
  170. {*******************************************************************}
  171. { PRE  : OldPalette moet de oude palette bevatten.                  }
  172. { POST : Oude Palette actief.                                       }
  173. {*******************************************************************}
  174. PROCEDURE RestoreColors;
  175. BEGIN
  176.   SetAllPalette(OldPalette);
  177. END;
  178.  
  179. {*******************************************************************}
  180. { DrawShadowBox(x,y,w,h);                                           }
  181. { Tekent een Shadowed-box.                                          }
  182. {*******************************************************************}
  183. { PRE  : VGAMode moet TRUE zijn (en dus geopend zijn!).             }
  184. { POST : Box op het sherm met schaduw rand.                         }
  185. {*******************************************************************}
  186. PROCEDURE DrawShadowBox(x,y,w,h:INTEGER);
  187. BEGIN
  188.   FixBar(x+3,y+3,x+w+3,y+h+3,DarkGray,DarkGray);  
  189.   FixBar(x,y,x+w,y+h,Yellow,Yellow);
  190. END;
  191.  
  192. {*******************************************************************}
  193. { DrawNodeBox(x,y);                                                 }
  194. { Tekent een NODE-Box voor de Linked-List.                          }
  195. {*******************************************************************}
  196. { PRE  : Heeft DrawShadowBox en VGAMode=TRUE nodig.                 }
  197. { POST : Een 3-delige box op het scherm.                            }
  198. {*******************************************************************}
  199. PROCEDURE DrawNodeBox(x,y: INTEGER);
  200. VAR
  201.   Teller : INTEGER;
  202. BEGIN
  203.   FOR Teller:=0 TO 2 DO
  204.     DrawShadowBox(x,y+(FormH+Dist)*Teller,FormW,FormH);
  205. END;
  206.  
  207. {*******************************************************************}
  208. { DrawPointer(x,y);                                                 }
  209. { Tekent een NODE-pointer voor de Linked-List (PIJL).               }
  210. {*******************************************************************}
  211. { PRE  : Heeft VGAMode=TRUE nodig.                                  }
  212. { POST : Pijl van Node n^.Next naar Node n+1^.Naam.                 }
  213. {*******************************************************************}
  214. PROCEDURE DrawPointer(x,y : INTEGER);
  215. BEGIN
  216.   y:=y+2*FormH+2*Dist+(FormH DIV 2);
  217.   x:=x+FormW-3*Dist;
  218.   SetColor(DarkGray);
  219.   SetFillStyle(SolidFill,DarkGray);
  220.   Circle(x,y,5);                                        { Cirkeltje }
  221.   SetColor(DarkGray);
  222.   FloodFill(x-3,y,DarkGray);                            { gevuld .. }
  223.   Bar(x+4,y-2,x+5*Dist,y+2);
  224.   Bar(x+5*Dist,y+2,x+5*Dist+4,y-2*FormH-2*Dist);
  225.   Bar(x+5*Dist+4,y-2*FormH-2*Dist,x+7*Dist,y-2*FormH-2*Dist+4);
  226.   PieSlice(x+8*Dist+4,y-2*FormH-2*Dist+2,138,215,10);
  227. END;
  228.  
  229. {*******************************************************************}
  230. { DrawMenu(x,y);                                                    }
  231. { Tekent option-menu (F1..F5).                                      }
  232. {*******************************************************************}
  233. { PRE  : Heeft DrawShadowBox en VGAMode=TRUE nodig.                 }
  234. { POST : Een Menu-Box voor de opties.                               }
  235. {*******************************************************************}
  236. PROCEDURE DrawMenu(x,y : INTEGER);
  237. BEGIN
  238.   DrawShadowBox(x,y,32*CX,17*CY);
  239.   SetColor(DarkGray);
  240.   OutTextXY(x+CX,y+CY,'Opties:');
  241.   OutTextXY(x+CX,y+3*CY, '1 Head Insertion Node');
  242.   OutTextXY(x+CX,y+5*CY, '2 Position Insertion Node');
  243.   OutTextXY(x+CX,y+7*CY, '3 Tail Insertion Node');
  244.   OutTextXY(x+CX,y+9*CY, '4 Remove Node');
  245.   OutTextXY(x+CX,y+11*CY,'5 Programma verlaten');
  246.   OutTextXY(x+CX,y+15*CY,'(Maximaal 5 Nodes toegestaan!)');
  247. END;
  248.  
  249. {*******************************************************************}
  250. { DrawNodeIndex;                                                    }
  251. { Tekent de balk met daarin de node nummering.                      }
  252. {*******************************************************************}
  253. { PRE  : VGAMode moet TRUE zijn, en de procedure DrawShadowBox      }
  254. {         moet aanwezig zijn.                                       }
  255. { POST : Een genummerde balk.                                       }
  256. {*******************************************************************}
  257. PROCEDURE DrawNodeIndex;
  258. BEGIN
  259.   DrawShadowBox(20,250,595,3*CX);
  260.   SetColor(DarkGray);
  261.   OutTextXY(20+CX ,250+CY,'[Nummer 1]');
  262.   OutTextXY(145+CX,250+CY,'[Nummer 2]');
  263.   OutTextXY(270+CX,250+CY,'[Nummer 3]');
  264.   OutTextXY(395+CX,250+CY,'[Nummer 4]');
  265.   OutTextXY(520+CX,250+CY,'[Nummer 5]');
  266. END;
  267.  
  268.   
  269. {*******************************************************************}
  270. {********************* DynamicList-Procedures **********************}
  271. {*******************************************************************}
  272.   
  273. {*******************************************************************}
  274. { EmptyList(StudentP);                                              }
  275. { Kijkt of een DynamischeLijst LEEG is. Een lege lijst is een lijst }
  276. { waarvoor nog geen 'new()' is gebruikt. StudentP wijst dus naar NIL}
  277. {*******************************************************************}
  278. { PRE  : Type 'StudentP' moet gedefinieerd zijn.                    }
  279. { POST : De functie geeft TRUE als de lijst leeg is, FALSE als de   }
  280. {        lijst niet leeg is.                                        }
  281. {*******************************************************************}
  282. FUNCTION EmptyList(Student : StudentP):BOOLEAN;
  283. BEGIN
  284.   IF Student=NIL THEN
  285.     EmptyList:=TRUE                 { Head=NIL betekent: LEGE lijst }
  286.   ELSE
  287.     EmptyList:=FALSE;
  288. END;
  289.  
  290. {*******************************************************************}
  291. { InputStudent(x,y,StudentP);                                       }
  292. { Invoer van de data voor 'StudentP'.                               }
  293. {*******************************************************************}
  294. { PRE  : 'StudentP' moet geinitialiseerd zijn met new().            }
  295. {        en VGAMode=TRUE.                                           }
  296. { POST : 'StudentP' bevat de nieuwe data.                           }
  297. {*******************************************************************}
  298. PROCEDURE InputStudent(x,y : INTEGER;VAR Current : StudentP);
  299. BEGIN
  300.   SetColor(Yellow);
  301.   DrawShadowBox(x-CX,y-CY,23*CX,7*CY);
  302.   SetColor(DarkGray);
  303.   OutTextXY(x,y,'Invoeren nieuwe node');
  304.   LeesInput(x,y+CY,'Naam:',Current^.Naam);
  305.   LeesInput(x,y+3*CY,'ANr :',Current^.ANr);
  306.   FixBar(x-Cx,y-3*CY,x+22*CX+Dist,y+6*CY+Dist,Black,Black);
  307. END;
  308.  
  309. {*******************************************************************}
  310. { OutputStudent(x,y,StudentP);                                      }
  311. { Weergave van de data die in de node 'StudentP' staat.             }
  312. {*******************************************************************}
  313. { PRE  : 'StudentP' moet geinitialiseerd zijn met new() en mag niet }
  314. {        leeg zijn.                                                 }
  315. { POST : De inhoud van StudentP op het scherm.                      }
  316. {*******************************************************************}
  317. PROCEDURE OutputStudent(x,y : INTEGER; Current : StudentP);
  318. BEGIN
  319.   DrawNodeBox(x,y);
  320.   SetColor(DarkGray);
  321.   OutTextXY(x+CX,y+CY,Current^.Naam);
  322.   OutTextXY(x+CX,y+CY+FormH+Dist,Current^.ANr);
  323.   IF Current^.Next=NIL THEN
  324.     OutTextXY(x+CX,Y+CY+2*FormH+2*Dist,'NIL')
  325.   ELSE
  326.     DrawPointer(x,y);
  327. END;
  328.  
  329. {*******************************************************************}
  330. { GotoEnd(StudentP);                                                }
  331. { Maakt van 'StudentP' de pointer naar de laatste node. Let dus op! }
  332. {*******************************************************************}
  333. { PRE  : Type 'StudentP' moet gedefinieerd zijn.                    }
  334. {         De lijst mag ook NIET leeg zijn !                         }
  335. { POST : 'StudenP' wijst nu naar de LAATSTE node in de lijst.       }
  336. {*******************************************************************}
  337. PROCEDURE GotoEnd(VAR Position : StudentP);
  338. BEGIN
  339.   WHILE Position^.Next<>NIL DO        { Laatste Node wijst naar NIL }
  340.     Position:=Position^.Next;
  341. END;
  342.  
  343. {*******************************************************************}
  344. { GotoNodeNr(n,StudentP);                                           }
  345. { Maakt van 'StudentP' de pointer naar de n-de node. Let dus op!    }
  346. {*******************************************************************}
  347. { PRE  : Type 'StudentP' moet gedefinieerd zijn.                    }
  348. {         De lijst mag ook NIET leeg zijn !                         }
  349. { POST : 'StudenP' wijst nu naar de n-de node in de lijst.          }
  350. {*******************************************************************}
  351. PROCEDURE GotoNodeNr(n : INTEGER; VAR Position : StudentP);
  352. VAR
  353.   Teller : INTEGER;
  354.   Temp   : StudentP;
  355. BEGIN
  356.   Position:=StudentHead;
  357.     FOR Teller:=2 TO n DO        { StudentHead is global 1e node !! }
  358.     BEGIN
  359.        IF Position^.Next<>NIL THEN { Laatste Node wijst naar NIL !! }
  360.       Position:=Position^.Next;
  361.     END;
  362. END;
  363.  
  364. {*******************************************************************}
  365. { HeadInsert(x,y,StudentP);                                         }
  366. { Initialiseerd indien nodig de lijst en voegt aan de kop van de    }
  367. { lijst een nieuwe node toe.                                        }
  368. {*******************************************************************}
  369. { PRE  : Type 'StudentP' moet gedefinieerd zijn.                    }
  370. { POST : De lijst is 1 node langer geworden, aan de kop !           }
  371. {*******************************************************************}
  372. PROCEDURE HeadInsert(x,y : INTEGER; VAR Head : StudentP);
  373. VAR
  374.   Node  : StudentP;
  375.   Empty : BOOLEAN;
  376. BEGIN
  377.   Empty:=EmptyList(Head);        { Kijk of de lijst leeg is         }
  378.   IF Empty THEN
  379.     BEGIN
  380.       NEW(Head);                 { Lege lijst wordt geinitialiseerd }
  381.       Node:=Head;                { Nieuw node = head, bij lege lijst}
  382.     END
  383.   ELSE
  384.     NEW(Node);                   { Er wordt een 'node' toegevoegd   }
  385.   InputStudent(x,y,Node);        { Invoer data van de node          }
  386.   IF Empty THEN
  387.     Node^.Next:=NIL
  388.   ELSE
  389.     BEGIN
  390.       Node^.Next:=Head;          { Vooraan schuiven van de node     }
  391.       Head:=Node;
  392.     END;
  393. END;
  394.  
  395. {*******************************************************************}
  396. { PositionInsert(x,y,StudentP);                                     }
  397. { Initialiseerd indien nodig de lijst en plaatst op POS een nieuwe  }
  398. { node in de lijst. Doet OOK position insert als: -de lijst leeg is }
  399. {                                                 -Maar 1 node heeft}
  400. {*******************************************************************}
  401. { PRE  : Type 'StudentP' moet gedefinieerd zijn.                    }
  402. { POST : De lijst is 1 node langer geworden.                        }
  403. {*******************************************************************}
  404. PROCEDURE PositionInsert(x,y : INTEGER; VAR Head : StudentP);
  405. VAR
  406.   Node     : StudentP;
  407.   Position : StudentP;
  408.   Empty    : BOOLEAN;
  409.   Invoer   : string[15];
  410.   Nr       : INTEGER;
  411.   
  412. BEGIN
  413.   Empty:=EmptyList(Head);        { Kijk of de lijst leeg is         }
  414.   IF Empty THEN
  415.     BEGIN
  416.       NEW(Head);                 { Lege lijst wordt geinitialiseerd }
  417.       Node:=Head;                { Nieuw node = head, bij lege lijst}
  418.       Node^.Next:=NIL;           { eerste en laatse Node            }
  419.     END
  420.   ELSE IF ActiveNodes<2 THEN
  421.     BEGIN
  422.       NEW(Node);
  423.       Head^.Next:=Node;
  424.       Node^.Next:=NIL;
  425.     END 
  426.   ELSE IF ActiveNodes>1 THEN
  427.     BEGIN
  428.       NEW(Node);                  { Er wordt een 'node' toegevoegd  }
  429.       Position:=Head;
  430.       Invoer:='Positie nummer [1-';
  431.       Invoer:=ConCat(Invoer,CHR(48+ActiveNodes),']: ');
  432.       REPEAT                      { Read 1-ActiveNodes (max=5)      }
  433.         SetColor(Yellow);
  434.         SetFillStyle(SolidFill,Yellow);
  435.         DrawShadowBox(x-CX,y-CY,23*CX,3*CY);
  436.         SetColor(DarkGray);
  437.         OutTextXY(x,y,Invoer);
  438.         c:=readKey;
  439.       UNTIL ((c>#48)AND(c<CHR(48+ActiveNodes+1)));
  440.       Nr:=ORD(c)-48;    
  441.       GotoNodeNr(Nr-1,Position);  { Add after n-1                   }
  442.     END;
  443.   InputStudent(x,y,Node);         { Invoer data van de node         }
  444.   IF (NOT(Empty)AND(ActiveNodes>1)) THEN
  445.     BEGIN  
  446.       Node^.Next:=Position^.Next;
  447.       Position^.Next:=Node;
  448.     END
  449.   ELSE IF Empty THEN
  450.     Head:=Node;
  451. END;
  452.  
  453. {*******************************************************************}
  454. { TailInsert(x,y,StudentP);                                         }
  455. { Initialiseerd indien nodig de lijst en voegt aan de staart van de }
  456. { lijst een nieuwe node toe.                                        }
  457. {*******************************************************************}
  458. { PRE  : Type 'StudentP' moet gedefinieerd zijn.                    }
  459. { POST : De lijst is 1 node langer geworden, aan de staart !        }
  460. {*******************************************************************}
  461. PROCEDURE TailInsert(x,y : INTEGER; VAR Head : StudentP);
  462. VAR
  463.   Node  : StudentP;
  464.   Tail  : StudentP;
  465.   Empty : BOOLEAN;
  466. BEGIN
  467.   Empty:=EmptyList(Head);        { Kijk of de lijst leeg is         }
  468.   IF Empty THEN
  469.     BEGIN
  470.       NEW(Head);                 { Lege lijst wordt geinitialiseerd }
  471.       Node:=Head;                { Nieuw node = head, bij lege lijst}
  472.     END
  473.   ELSE
  474.     BEGIN
  475.       NEW(Node);                 { Er wordt een 'node' toegevoegd   }
  476.       Tail:=Head;
  477.       GotoEnd(Tail);
  478.     END;
  479.   InputStudent(x,y,Node);        { Invoer data van de node          }
  480.    Node^.Next:=NIL;
  481.   IF NOT(Empty) THEN
  482.     Tail^.Next:=Node             { Achteraan schuiven van de node   }
  483.   ELSE
  484.     Head:=Node;
  485. END;
  486.  
  487. {*******************************************************************}    
  488. { ShowList(x,y,StudentP);                                           }
  489. { Laat alle nodes in een lijst zien, te beginnen bij de node die    }
  490. { als parameter gegeven wordt (studentP).                           }
  491. {*******************************************************************}
  492. { PRE  : Type 'StudentP' moet gedefinieerd zijn.                    }
  493. { POST : Als de lijst niet leeg is, is de hele lijst zichtbaar      }
  494. {        vanaf 'StudentP'.                                          }
  495. {*******************************************************************}
  496. PROCEDURE ShowList(x,y : INTEGER;Head : StudentP);
  497. BEGIN
  498.   IF NOT(EmptyList(Head)) THEN
  499.     BEGIN
  500.       OutputStudent(x,y,Head);
  501.       x:=x+FormW+6*Dist;    
  502.       ShowList(x,y,Head^.Next);      { recursion }
  503.     END;
  504. END;
  505.  
  506. {*******************************************************************}  
  507. { DeleteNode(x,y);                                                  }
  508. { Verwijderd een node, nummer wordt afgevraagd.                     }
  509. {*******************************************************************}
  510. { PRE  : Er moet minstens 1 node in de list staan.                  }
  511. { POST : 1 element minder in de list.                               }  
  512. {*******************************************************************}  
  513. PROCEDURE DeleteNode(x,y : INTEGER);
  514. VAR
  515.   Nr       : INTEGER;
  516.   Position : StudentP;
  517.   BadNode  : StudentP;
  518.   Invoer   : string[35];
  519. BEGIN
  520.   Position:=StudentHead;
  521.   IF StudentHead^.Next=NIL THEN
  522.     DISPOSE(StudentHead)
  523.   ELSE    
  524.     BEGIN  
  525.       Invoer:='Verwijder Positie nummer [1-';
  526.       Invoer:=ConCat(Invoer,CHR(48+ActiveNodes),']: ');
  527.       REPEAT                      { Read 1-ActiveNodes (max=5)      }
  528.         SetColor(Yellow);
  529.         SetFillStyle(SolidFill,Yellow);
  530.         DrawShadowBox(x-CX,y-CY,36*CX,3*CY);
  531.         SetColor(DarkGray);
  532.         OutTextXY(x,y,Invoer);
  533.         c:=readKey;
  534.       UNTIL ((c>#48)AND(c<=CHR(48+ActiveNodes+1)));
  535.       Nr:=ORD(c)-48;              { pos 2 =  insert NA pos 1        }  
  536.     IF Nr>1 THEN
  537.       BEGIN
  538.         GotoNodeNr(Nr-1,Position);
  539.         BadNode:=Position^.Next;
  540.         Position^.Next:=BadNode^.Next;                { Wipe Node   }
  541.         DISPOSE(BadNode);                             { free memory }    
  542.       END
  543.     ELSE 
  544.       BEGIN
  545.         BadNode:=StudentHead;
  546.         StudentHead:=BadNode^.Next;
  547.         DISPOSE(BadNode);
  548.       END;
  549.     END;
  550.     FixBar(x-CX,y-CY,x+36*CX+Dist,y+4*CY,Black,Black);
  551. END;
  552.  
  553. {*******************************************************************}
  554. { ClearList;                                                        }
  555. { Verwijderd de LinkedList uit het geheugen, reserved memory komt   }
  556. { nu vrij voor andere toepassingen.                                 }
  557. {*******************************************************************}
  558. { PRE  : De globale variable STUDENTHEAD moet bestaan.              }
  559. { POST : Een lege lijst.                                            }
  560. {*******************************************************************}
  561. PROCEDURE ClearList;
  562. VAR
  563.   Temp : StudentP;
  564. BEGIN
  565.   WHILE NOT(EmptyList(StudentHead)) DO
  566.   BEGIN
  567.     Temp:=StudentHead^.Next;
  568.     DISPOSE(StudentHead);
  569.     StudentHead:=Temp;
  570.   END;
  571. END;
  572.  
  573. {*******************************************************************}
  574. { ReadMenuKeys;                                                     }
  575. { Leest het toetsenbord voor de menu opties.                        }
  576. {*******************************************************************}
  577. { PRE  : Werkt met HeadInsert, PositionInsert, TailInsert en        }
  578. {         ShowList, deze moeten dus aanwezig zijn.                  }
  579. { POST : -                                                          }
  580. {*******************************************************************}
  581. PROCEDURE ReadMenuKeys;
  582. BEGIN
  583.   REPEAT 
  584.     c:=ReadKey;
  585.     CASE c OF
  586.       '1' : BEGIN
  587.                IF ActiveNodes<MaxNodes THEN
  588.                 BEGIN
  589.                   HeadInsert(20,80,StudentHead);      { 1 }
  590.                   ShowList(20,300,StudentHead);
  591.                   ActiveNodes:=SUCC(ActiveNodes);
  592.                 END;
  593.             END;
  594.       '2' : BEGIN
  595.                IF ActiveNodes<MaxNodes THEN
  596.                 BEGIN
  597.                   PositionInsert(20,80,StudentHead);  { 2 }
  598.                   ShowList(20,300,StudentHead);
  599.                   ActiveNodes:=SUCC(ActiveNodes);
  600.                 END;
  601.             END;
  602.       '3' : BEGIN
  603.               IF ActiveNodes<MaxNodes THEN
  604.                 BEGIN
  605.                   TailInsert(20,80,StudentHead);      { 3 }
  606.                   ActiveNodes:=SUCC(ActiveNodes);
  607.                   ShowList(20,300,StudentHead);
  608.                 END
  609.             END;
  610.       '4' : BEGIN
  611.               IF ActiveNodes>1 THEN
  612.                 BEGIN
  613.                   DeleteNode(20,80);                  { 4 }
  614.                   FixBar(20,300,650,450,Black,Black);
  615.                   ActiveNodes:=PRED(ActiveNodes);
  616.                 END
  617.               ELSE
  618.                 BEGIN
  619.                   ClearList;
  620.                   StudentHead:=NIL;
  621.                   FixBar(20,300,599,400,Black,Black);
  622.                   ActiveNodes:=0;
  623.                 END;
  624.               ShowList(20,300,StudentHead);
  625.             END;
  626.       '5' : exit;                                      { 5 }
  627.       END;
  628.   UNTIL FALSE;
  629. END;
  630.   
  631. {*******************************************************************}
  632. {******************************* MAIN ******************************}
  633. {*******************************************************************}
  634. BEGIN
  635.   ActiveNodes:=0;
  636.   StudentHead:=NIL;       { Nog lege lijst  }
  637.   OpenVGAScreen;          { VGAHi openen    }
  638.   IF VGAMode THEN         { VGAHi is nodig! }
  639.   BEGIN
  640.       DrawNodeIndex;      { Node nummering  }
  641.       DrawMenu(380,72);   { Menu tekenen    }
  642.       ReadMenuKeys;       { Menu afwachten  }
  643.       RestoreColors;      { Herstel kleuren }
  644.       CloseGraph;         { VGAHi Sluiten   }
  645.       ClearList;          { Release memory  }
  646.   END;
  647. END.                      { doei !          }
  648.  
  649.